<template>
	<view class="b-t">
		<view class="list b-b" v-for="item in addressList" @click="checkAddress(item)">
			<view class="wrapper">
				<view class="address-box">
					<text v-if="item.defaultVal == 1" class="tag">默认</text>
					<text class="address">{{item.areaAllName}}</text>
				</view>
				<view class="u-box">
					<text class="name">{{item.trueName}}</text>
					<text class="mobile">{{item.mobileNum}}</text>
				</view>
			</view>
			<text class="yticon icon-bianji" @click.stop="addAddress('edit', item)"></text>
		</view>
		
		<button class="add" @click="addAddress('add')">新增地址</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList:[],
				source: 0
			}
		},
		onLoad(option) {
			this.source = option.source;
			
			this.getAddress();
		},
		methods: {
			checkAddress(item){
				
				if(this.source == 1) {
					this.$api.prePage().addressInfo = item;
					uni.navigateBack();
				}
			},
			async getAddress() {
				let data = {
					"userId": "1064698066201870336"
				}
				
				let res = await this.helper.requestAPI(this.api.addrlist,data);
				let addressInfo = res.body;
				this.addressList = addressInfo.addressList;
			},
			addAddress(type,item){
				uni.navigateTo({
					url: `./addressManage?type=${type}&data=${JSON.stringify(item)}`
				});
			},
			refreshList(){
				this.getAddress();
			}
		}
	}
</script>

<style lang="scss">
	.list{
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;;
		background: #fff;
		position: relative;
	}
	
	.wrapper{
		display: flex;
		flex-direction: column;
		flex: 1;
	}
	.address-box{
		display: flex;
		align-items: center;
		
		.tag{
			font-size: 22rpx;
			color: $base-color;
			margin-right: 10rpx;
			background: #fffafb;
			border: 1px solid #ffb4c7;
			border-radius: 4rpx;
			padding: 4rpx 5rpx;
			line-height: 1;
		}
		.address{
			font-size: 28rpx;
			color: $font-color-dark;
		}
	}
	.u-box{
		font-size: 28rpx;
		color: $font-color-light;
		margin-top: 16rpx;
		.name{
			margin-right: 30rpx;
		}
	}
	.icon-bianji{
		display: flex;
		align-items: center;
		height: 80rpx;
		font-size: 40rpx;
		color: $font-color-light;
		padding-left: 30rpx;
	}
	
	.add {
		position: absolute;
		left: 5%;
		bottom: 20rpx;
		width: 90%;
		font-size: 28rpx;
		background-color: $base-color;
		
		display: flex;
		justify-content: center;
		align-items: center;
		height: 80rpx;
		color: white;
		border-radius: 10rpx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
</style>
